package com.xc.freeapp.diseases.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.xc.freeapp.account.controller.AbstractController;
import com.xc.freeapp.bean.AuthInfo;
import com.xc.freeapp.common.ResponseBean;
import com.xc.freeapp.entity.Diseasesdetail;
import com.xc.freeapp.entity.Takemedic;
import com.xc.freeapp.exception.BaseException;
import com.xc.freeapp.service.DiseasesService;
import com.xc.freeapp.service.TakemedicService;
import com.xc.freeapp.util.AuthUtil;
import com.xc.freeapp.util.TokenAnnotation;

@Controller
@RequestMapping("/diseases")
@Api(value="/diseases",description = "疾病信息")
public class DiseasesController extends AbstractController{

	private Logger log = Logger.getLogger(this.getClass());


	@Autowired
	private DiseasesService diseasesService;


	/**
	 * 根据疾病id查询疾病详情
	 */
	@TokenAnnotation(required=false)
	@RequestMapping(value = "{id}", method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation(value = "根据疾病id查询疾病详情")
	public Map<String,Object> getDiseasesdetail(@PathVariable("id") String diseasesId)
			throws BaseException {
		log.info("根据疾病id" + diseasesId + "查询疾病详情！");
		Diseasesdetail diseasesdetail = diseasesService
				.selectByPrimaryKey(Integer.parseInt(diseasesId));
		Map<String, Object> map = new HashMap<String, Object>();
		if (diseasesdetail != null) {

			map.put("id", diseasesdetail.getId());
			map.put("name", diseasesdetail.getName());
			map.put("description", diseasesdetail.getDescription());

			List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
			Map<String, Object> innermap1 = new HashMap<String, Object>();
			innermap1.put("title", "症状");
			innermap1.put("content",
					diseasesdetail.getSymptoms().replace("\r\n", "<br/>")
							.replaceAll("\n", "<br/>"));
			Map<String, Object> innermap2 = new HashMap<String, Object>();
			innermap2.put("title", "检查");
			innermap2.put("content",
					diseasesdetail.getCheckups().replace("\r\n", "<br/>")
							.replaceAll("\n", "<br/>"));
			Map<String, Object> innermap3 = new HashMap<String, Object>();
			innermap3.put("title", "治疗");
			innermap3.put("content",
					diseasesdetail.getCure().replace("\r\n", "<br/>")
							.replaceAll("\n", "<br/>"));
			Map<String, Object> innermap4 = new HashMap<String, Object>();
			innermap4.put("title", "预防及预后");
			innermap4.put("content",
					diseasesdetail.getPrevention().replace("\r\n", "<br/>")
							.replaceAll("\n", "<br/>"));
			list.add(innermap1);
			list.add(innermap2);
			list.add(innermap3);
			list.add(innermap4);
			map.put("contentdata", list);

		}
		
		return map;
	}

}
